<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
		<title>查询服务-签约情况-报告查询-新生儿遗传代谢病筛查</title>
		<script type="text/javascript" src="js/init.js"></script>
		<link rel="stylesheet" type="text/css" href="css/common.css">
		<link rel="stylesheet" type="text/css" href="css/upload.css">
	</head>
	<body>
		<div class="upload-main">
			<div class="title">上传贷款分期资料信息</div>
			<div class="txt">尊敬的用户，请将您在新易贷中填写的贷款信息，以截图、拍照等图片的形式上传，方便我们信息审核，上限10张，谢谢合作！</div>
			<div class="up clear" id="container">
				<div class="came-con">
					<a href="javascript:;" class="came up-btn" id="came"></a>
				</div>
				<div class="pictuer-con">
					<a href="javascript:;" class="pictuer up-btn" id="pickfiles"></a>
				</div>
			</div>
			<div class="up-list">
				<div class="up-item"><img src="images/top.png" alt=""><a href="javascript:;" class="remove">&#x2716;</a></div>
				<div class="up-item"><img src="images/top.png" alt=""><a href="javascript:;" class="remove">&#x2716;</a></div>
			</div>
		</div>			
	</body>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/qiniu/moxie.js"></script>
    <script type="text/javascript" src="js/qiniu/plupload.dev.js"></script>
    <script type="text/javascript" src="js/qiniu/zh_CN.js"></script>
    <script type="text/javascript" src="js/qiniu/ui.js"></script>
    <script type="text/javascript" src="js/qiniu/qiniu.js"></script>
    <script type="text/javascript" src="js/base64.min.js"></script>
    <script type="text/javascript" src="js/sha1.js"></script>
	<script type="text/javascript">
		$(function(){
			//构建upkoken
			//策略
			var putPolicy = {
			    "scope":                "image",
			    "deadline":             new Date().valueOf() + 3600,
			    "mimeLimit":  			"image/*"
			}
			
			//key
			var accessKey = "";
			var secretKey = "";

			var getToken = function(accessKey, secretKey, putPolicy) {
				if(accessKey && secretKey && putPolicy) {
			        //SETP 2
			        var put_policy = JSON.stringify(putPolicy);

			        //SETP 3
			        var encoded = Base64.encode(JSON.stringify(putPolicy)).replace(/\+/g, "-",).replace(/\//g, "_");

			        //SETP 4
			        var hash = HmacSHA1(secretKey, encoded);
			        var encodedSign  = hash.replace(/\+/g, "-",).replace(/\//g, "_");

			        //SETP 5
			        var upload_token = accessKey + ":" + encodedSign + ":" + encoded;
			        return upload_token;
		        }else {
		        	return "";
		        }
		    };		

		    var param = {
				    runtimes: 'html5,flash,html4',      // 上传模式，依次退化
				    uptoken : getToken(accessKey, secretKey, putPolicy), // uptoken是上传凭证，由其他程序生成			   
				    get_new_uptoken: false,             // 设置上传文件的时候是否每次都重新获取新的uptoken则开启，SDK在前端将不对key进行任何处理
				    domain: 'ofld5g7th.bkt.clouddn.com',     // bucket域名，下载资源时用到，必需
				    container: 'container',             // 上传区域DOM ID，默认是browser_button的父元素
				    max_file_size: '100mb',             // 最大文件体积限制
				    flash_swf_url: 'path/of/plupload/Moxie.swf',  //引入flash，相对路径
				    max_retries: 3,                     // 上传失败最大重试次数
				    dragdrop: true,                     // 开启可拖曳上传
				    drop_element: 'container',          // 拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传
				    chunk_size: '4mb',                  // 分块上传时，每块的体积
				    auto_start: true,                  // 选择文件后自动上传，若关闭需要自己绑定事件触发上传
				    init: {	          
				        'FileUploaded': function(up, file, info) {
				               // 每个文件上传成功后，处理相关的事情
				               // 其中info是文件上传成功后，服务端返回的json，形式如：
				               // {
				               //    "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
				               //    "key": "gogopher.jpg"
				               //  }
				               // 查看简单反馈
				                var domain = up.getOption('domain');
				                var res = JSON.parse(info.response);
				                var sourceLink = 'http://'+domain +"/"+ res.key; 

				                if($(".up-item").length <= 10) {
					                var _html = '<div class="up-item">'
					               			+'	<img src="'+sourceLink+'" alt="">'
					               			+'	<a href="javascript:;" class="remove">&#x2716;</a>'
					               			+'</div>'
					                $(".up-list").append(_html);
				                }else {
				                	//最多上传10个
				                	$.toast("最多上传10个");
				                }

				        },
				        'Error': function(up, err, errTip) {
				               //上传出错时，处理相关的事情
				        },
				        'UploadComplete': function() {
				               //队列文件处理完毕后，处理相关的事情
				        },	     
				    }
			}

			// 上传选择的点选按钮，必需
			param.browse_button = 'came';        
			var Qiniu1 = new QiniuJsSDK();		
			var uploader1 = Qiniu1.uploader(param);	

			// 上传选择的点选按钮，必需
			param.browse_button = 'pickfiles';   
			var Qiniu2 = new QiniuJsSDK();
			var uploader2 = Qiniu2.uploader(param);		


			$(".up-list").on("click", ".remove", function() {
				$(this).parent().remove();

				//ajax
			})
		});
	</script>
</html>
